<?php
header("Content-type:text/html; charset=utf-8");

class Mysql{
	private $mysql,$result,$result_array_one,$result_array_all;
	function __construct(){
		$this->mysql=new PDO("mysql:host=localhost;dbname=ruiyou_info","root","root");
		$this->result_array_one=array();
		$this->result_array_all=array();
		$this->mysql->query("set names utf8");
	}
	
	function addDevice($type,$number,$product,$info,$mac,$os,$version,$other){
		$insert=$this->mysql->prepare("insert into device_item(type,number,product,info,mac,os,version,other) values ('$type','$number','$product','$info','$mac','$os','$version','$other')");
		$status=$insert->execute();
		if($status){
			return 1;
		}else{
			return 0;
		}
	}
	
	function getDevice(){
		$select=$this->mysql->prepare("select * from device_item");
		$select->execute();
		while($row=$select->fetch(PDO::FETCH_ASSOC)){
			$this->result_array_one['type']=$row['type'];
			$this->result_array_one['number']=$row['number'];
			$this->result_array_one['product']=$row['product'];
			$this->result_array_one['info']=$row['info'];
			$this->result_array_one['mac']=$row['mac'];
			$this->result_array_one['os']=$row['os'];
			$this->result_array_one['version']=$row['version'];
			$this->result_array_one['other']=$row['other'];
			
			array_push($this->result_array_all,$this->result_array_one);
		}
		
		return $this->result_array_all;
		$this->result_array_all=array();
	}
	
	function getSelectDevice($keyword){
		$select=$this->mysql->prepare("select * from device_item where type like '%$keyword%'");
		$select->execute();
		while($row=$select->fetch(PDO::FETCH_ASSOC)){
			$this->result_array_one['type']=$row['type'];
			$this->result_array_one['number']=$row['number'];
			$this->result_array_one['product']=$row['product'];
			$this->result_array_one['info']=$row['info'];
			$this->result_array_one['mac']=$row['mac'];
			$this->result_array_one['os']=$row['os'];
			$this->result_array_one['version']=$row['version'];
			$this->result_array_one['other']=$row['other'];
			
			array_push($this->result_array_all,$this->result_array_one);
		}
		
		return $this->result_array_all;
		$this->result_array_all=array();
	}
	
	function __destruct(){
		$this->mysql=NULL;
	}
}

function alert($string){
	echo "<script language='javascript'>";
	echo "alert('$string');";
	echo "</script>";
}

function open($string,$string2){
	echo "<script language='javascript'>";
	echo "window.open('$string','$string2');";
	echo "</script>";
}